package com.mojo.concurrent.threadsafe;

/**
 * 线程异常
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2021, 广州九尾信息科技有限公司
 * @date 2021/8/17 15:42
 */
public class ThreadException01 {
    public static void main(String[] args) {
        Thread01 thread01 = new Thread01();
        Thread thread = new Thread(thread01);
        thread.start();
        //线程处于阻塞状态时，如调用wait，sleep，join。此时抛出InterruptException，如果没有阻塞，则interrupt()不起作用；
        thread.interrupt();
    }
}

class Thread01 implements Runnable {
    @Override
    public void run() {
        Thread thread = new Thread(new Thread02(), "线程Thread02");
        thread.start();
        //join方法会阻塞，抛出interruptException异常
        //try {
        //    thread.join();
        //} catch (InterruptedException e) {
        //    System.out.println("++++");
        //    e.printStackTrace();
        //}
        System.out.println(">>>>>>");
    }
}

class Thread02 implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());

    }
}
